package com.cloud.springbootcloud.controller;

import com.cloud.springbootcloud.pojo.Product;
import com.cloud.springbootcloud.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/product")
public class ProductController {
    @Autowired
    private ProductService productService;
    @GetMapping("/list")
    @ResponseBody
    public List<Product> selectProductList(){
        return productService.selectProductList();
    }

    /**
     * 查询商品
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ResponseBody
    public Product selectProductById(@PathVariable("id")Integer id){

        return productService.selectProductById(id);
    }

    @PostMapping("/single")
    @ResponseBody
    public Product queryProductById(Integer id){

        return productService.queryProductById(id);
    }

    @PostMapping("/save")
    @ResponseBody
    public Map<Object,Object> createProduct(
            @RequestBody Product product){

        return productService.createProduct(product);
    }

}
